<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <canvas
      id="canvas"
      style="border: 1px solid #cccccc; margin: 100px auto"
    ></canvas>
    <script>
      window.onload = function () {
        const canvas = document.querySelector("#canvas");
        canvas.width = 1024;
        canvas.height = 768;
        if (canvas.getContext("2d")) {
          const context = canvas.getContext("2d");
          context.beginPath();
          context.moveTo(100, 100);
          context.lineTo(700, 700);
          context.lineTo(100, 700);
          context.lineTo(100, 100);
          context.closePath();

          /*      context.fillStyle = "blue";
            context.fill();*/
          context.lineWidth = 5;
          context.strokeStyle = "#ccc";
          context.stroke();
          context.beginPath();
          context.moveTo(100, 200);
          context.lineTo(700, 1000);
          context.closePath();

          context.strokeStyle = "red";

          context.stroke();
        } else {
          alert("浏览器不支持canvas");
        }
      };
    </script>
  </body>
</html>
